From 50b90adc279fe6b5bbd317c69dd88ce29b3219fa Mon Sep 17 00:00:00 2001 From: robertl Date: Tue, 31 Aug 2004 20:54:23 +0000 Subject: [PATCH] Trickle in a bit of Garmin/USB support that isn't disruptive. --- gpsbabel/jeeps/garminusb.h | 58 ++++++++++++++++++++++++++++++++++++++ gpsbabel/jeeps/gps.h | 1 + gpsbabel/jeeps/gpsapp.c | 22 +++++++++------ 3 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 gpsbabel/jeeps/garminusb.h diff --git a/gpsbabel/jeeps/garminusb.h b/gpsbabel/jeeps/garminusb.h new file mode 100644 index 000000000..2a063a95f --- /dev/null +++ b/gpsbabel/jeeps/garminusb.h @@ -0,0 +1,58 @@ +/* + Definitions for Garmin USB protocol and implementation. + + Copyright (C) 2004 Robert Lipe, robertlipe@usa.net + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + + */ +#include + +/* This structure is a bit funny looking to avoid variable length + * arrays which aren't present in C89. This contains the visible + * fields in the USB packets of the Garmin USB receivers (60C, 76C, etc.) + * All data are little endian. + */ +typedef +union { + struct { + unsigned char type; + unsigned char reserved1; + unsigned char reserved2; + unsigned char reserved3; + unsigned char pkt_id[2]; + unsigned char reserved6; + unsigned char reserved7; + unsigned char datasz[4]; + unsigned char databuf[1]; /* actually an variable length array... */ + } gusb_pkt; + unsigned char dbuf[MAX_GPS_PACKET_SIZE]; +} garmin_usb_packet; + +/* + * Internal interfaces that are common regardless of underlying + * OS implementation. + */ +#define GUSB_MAX_UNITS 20 +struct { + unsigned long serial_number; + char *os_identifier; /* In case the OS has another name for it. */ + char *product_identifier; /* From the hardware itself. */ +} garmin_unit_info[GUSB_MAX_UNITS]; + +int gusb_cmd_send(const garmin_usb_packet *obuf, size_t sz); +int gusb_cmd_get(garmin_usb_packet *ibuf, size_t sz); +int gusb_open(const char *portname); +int gusb_close(void); diff --git a/gpsbabel/jeeps/gps.h b/gpsbabel/jeeps/gps.h index 746092bc9..8abd464db 100644 --- a/gpsbabel/jeeps/gps.h +++ b/gpsbabel/jeeps/gps.h @@ -177,6 +177,7 @@ double gps_save_lon; extern int32 gps_save_id; extern double gps_save_version; extern char gps_save_string[GPS_ARB_LEN]; +extern int gps_is_usb; extern struct COMMANDDATA COMMAND_ID[2]; diff --git a/gpsbabel/jeeps/gpsapp.c b/gpsbabel/jeeps/gpsapp.c index 594d60e09..9322b082a 100644 --- a/gpsbabel/jeeps/gpsapp.c +++ b/gpsbabel/jeeps/gpsapp.c @@ -97,9 +97,10 @@ static void GPS_D550_Send(UC *data, GPS_PAlmanac alm); static void GPS_D551_Send(UC *data, GPS_PAlmanac alm); -int32 gps_save_id; -double gps_save_version; -char gps_save_string[GPS_ARB_LEN]; +int32 gps_save_id; +int gps_is_usb; +double gps_save_version; +char gps_save_string[GPS_ARB_LEN]; /* @func GPS_Init ****************************************************** @@ -118,9 +119,16 @@ int32 GPS_Init(const char *port) int32 ret; (void) GPS_Util_Little(); + + /* + * Decide here if the portname refers to a USB device and set the + * global that's used as in inflection point for other decisions later. + */ + gps_is_usb = (0 == strncmp(port, "usb:", 4)); + ret = GPS_A000(port); if(ret<0) return ret; - + if (gps_is_usb) return 1; gps_save_time = GPS_Command_Get_Time(port); if(!gps_save_time) { return FRAMING_ERROR; @@ -154,12 +162,12 @@ static int32 GPS_A000(const char *port) if(!GPS_Serial_On(port, &fd)) return gps_errno; - if(!GPS_Serial_Flush(fd)) + if(!gps_is_usb && !GPS_Serial_Flush(fd)) return gps_errno; if(!(tra = GPS_Packet_New()) || !(rec = GPS_Packet_New())) return MEMORY_ERROR; - + GPS_Make_Packet(&tra, LINK_ID[0].Pid_Product_Rqst,NULL,0); if(!GPS_Write_Packet(fd,tra)) return SERIAL_ERROR; @@ -182,8 +190,6 @@ static int32 GPS_A000(const char *port) (void) sprintf(tstr, "Version:\t%.2f\n",gps_save_version); GPS_User(tstr); - - gps_date_time_transfer = pA600; -- 2.30.2